﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyRoguelike.Game.Objects;

//Todo: methods OnItem, OffItem
namespace MyRoguelike.Game.Items
{
    class Inventory
    {
        private List<GameItem> _lstItems = new List<GameItem>();

        private GameObject _gameObject;

        public GameObject GameObject
        {
            get { return _gameObject; }
        }

        public List<GameItem> Items
        {
            get { return _lstItems; }
        }

        public Inventory(GameObject gameObject)
        {
            _gameObject = gameObject;
        }

        /// <summary>
        /// Add item to inventory
        /// </summary>
        /// <param name="gameItem">Item</param>
        /// <returns>Added item</returns>
        public GameItem AddItem(GameItem gameItem)
        {
            gameItem.GameObj = _gameObject;
            _lstItems.Add(gameItem);

            return gameItem;
        }

        /// <summary>
        /// Delete item from inventory
        /// </summary>
        /// <param name="gameItem">Item</param>
        public void DeleteItem(GameItem gameItem)
        {
            if (_lstItems.Contains(gameItem))
                _lstItems.Remove(gameItem);
        }

        /// <summary>
        /// Use item
        /// </summary>
        /// <param name="gameItem">Item</param>
        public void UseItem(GameItem gameItem)
        {
           if (_lstItems.Contains(gameItem))
           {
               // If item is not equip
               if (!gameItem.IsEquip)
               {
                   // Use item and remove it after use
                   if (gameItem.Use())
                       _lstItems.Remove(gameItem);
               }
           }
        }

    }
}
